package com.ruoyi.ruoyiqywechat.controller;


import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.qy.domain.User;
import com.ruoyi.common.qy.request.RegisterThirdUserRequest;
import com.ruoyi.common.qy.request.WxBindingPhoneRequest;
import com.ruoyi.common.qy.response.LoginResponse;
import com.ruoyi.ruoyiqywechat.service.UserCenterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 微信缓存表 前端控制器
 *  +----------------------------------------------------------------------
 *  | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 *  +----------------------------------------------------------------------
 *  | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
 *  +----------------------------------------------------------------------
 *  | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 *  +----------------------------------------------------------------------
 *  | Author: CRMEB Team <admin@crmeb.com>
 *  +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("/wechat")
//(tags = "微信 -- 开放平台")
public class WeChatController {

    @Autowired
    private UserCenterService userCenterService;

    /**
     * 微信登录小程序授权登录
     */
    //(value = "微信登录小程序授权登录")
    @RequestMapping(value = "/authorize/program/login", method = RequestMethod.POST)
    public R<LoginResponse> programLogin(@RequestParam String code, @RequestBody @Validated RegisterThirdUserRequest request){
        return R.ok(userCenterService.weChatAuthorizeProgramLogin(code, request));
    }

    /**
     * 微信注册绑定手机号wechatUser/info,
     */
    //(value = "微信注册绑定手机号")
    @RequestMapping(value = "/register/binding/phone", method = RequestMethod.POST)
    public R<LoginResponse> registerBindingPhone(@RequestBody @Validated WxBindingPhoneRequest request){
        return R.ok(userCenterService.registerBindingPhone(request));
    }
    /**
     * 微信登录公众号授权登录通过微信code登录
     * @param code 公众号授权后的code
     * @param sendUserId 绑定的微信用户
     */
    @RequestMapping(value = "/authorize/login", method = RequestMethod.GET)
    public R<LoginResponse> login(@RequestParam(value = "code") String code,@RequestParam("sendUserId") String sendUserId){
        return R.ok(userCenterService.weChatAuthorizeLogin(code,sendUserId));
    }



}



